#ifndef __ICM206XX_H
#define __ICM206XX_H

#ifdef __cplusplus
extern "C"{
#endif

#include "user_i2c.h"

typedef enum
{
  WHO_AM_I_NULL=0x00,
	WHO_AM_I_MPU6050  =0x68,
	WHO_AM_I_ICM20689 =0x98,
	WHO_AM_I_ICM20608D=0xAE,
	WHO_AM_I_ICM20608G=0xAF,
	WHO_AM_I_ICM20602=0x12,
}imu_id_read;

/*********** 寄存器定义***********/
#define IMU_ICM20689_ID  0x98
#define ICM20689_ADRESS		0x68

#define	SMPLRT_DIV		0x19
#define	MPU_CONFIG		0x1A
#define	GYRO_CONFIG		0x1B
#define	ACCEL_CONFIG    0x1C
#define ACCEL_CONFIG2   0x1D
#define	ACCEL_XOUT_H	0x3B
#define	ACCEL_XOUT_L	0x3C
#define	ACCEL_YOUT_H	0x3D
#define	ACCEL_YOUT_L	0x3E
#define	ACCEL_ZOUT_H	0x3F
#define	ACCEL_ZOUT_L	0x40
#define	TEMP_OUT_H		0x41
#define	TEMP_OUT_L		0x42
#define	GYRO_XOUT_H		0x43
#define	GYRO_XOUT_L		0x44
#define	GYRO_YOUT_H		0x45
#define	GYRO_YOUT_L		0x46
#define	GYRO_ZOUT_H		0x47
#define	GYRO_ZOUT_L		0x48
#define	PWR_MGMT_1		0x6B
#define	WHO_AM_I		0x75
#define USER_CTRL		0x6A
#define INT_PIN_CFG		0x37

/*********** 状态码 ***********/
#define IMU_OK 0
#define IMU_NO_DATA_INPUT 1
#define IMU_NOT_READY 2
#define IMU_INIT_ERROR 3
#define IMU_DO_NOT_SUPPORT 4
#define IMU_DATA_LENGTH_OUT_OF_RANGE 5

/*********** IMU常量 ***********/
#define GYRO_CALIBRATION_COFF 0.0152672f;  //500,度/秒
#define ACC_CALIBRATION_COFF  0.0001221f;  //1/8192,米/秒2/G
#define GYRO_CALIBRATION_COFF_RAD 0.0002665f//弧度/秒
#define ACC_CALIBRATION_COFF_M 0.0011974f //米/秒2
// acceleration due to gravity in m/s/s
#define GRAVITY_MSS 9.80665f
#define GRAVITY_RAW 8192.0f
#define RAW_TO_G     GRAVITY_MSS/GRAVITY_RAW
#define G_TO_RAW  	 GRAVITY_RAW/GRAVITY_MSS

/********************全局函数声明********************/
int8_t icm206xx_init();
int8_t icm206xx_read_all(float* gyro_x,float* gyro_y,float* gyro_z,float* accel_x,float* accel_y,float* accel_z,float* temperature);

#ifdef __cplusplus
}
#endif

#endif
